#include<bits/stdc++.h>
#define int long long
#define N 500005
#define ls (x<<1)
#define rs ((x<<1)|1)
#define mid ((l+r)>>1)
using namespace std;
int n,q;
int a[N],s[N];
pair<int,int> f[N];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
inline pair<int,int> cmp(pair<int,int> x,pair<int,int> y){
    if((__int128)x.first*y.second>(__int128)y.first*x.second) return x;
    return y;
}
struct node{
    vector<pair<int,int> > t;
    void build(int x,int l,int r){
        if(l==r){
            t[x]=f[l];
            return;
        }
        build(ls,l,mid);
        build(rs,mid+1,r);
        t[x]=cmp(t[ls],t[rs]);
    }
    pair<int,int> query(int x,int l,int r,int L,int R){
        if(L<=l&&r<=R) return t[x];
        if(R<=mid) return query(ls,l,mid,L,R);
        if(L>mid) return query(rs,mid+1,r,L,R);
        pair<int,int> ll=query(ls,l,mid,L,R),rr=query(rs,mid+1,r,L,R);
        return cmp(ll,rr);
    }
};
vector<node> T;
inline void sol(int x){
    for(int i=x;i<=n;++i){
        int h=s[i]-s[i-x];
        f[i]={h*h,x};
        if(h==0) f[i].second=1;
        else{
            int o=__gcd(f[i].first,f[i].second);
            f[i].first/=o,f[i].second/=o;
        }
    }
    T[x].t.resize((n<<2)+5);
    T[x].build(1,x,n);
}
signed main(){
    freopen("value.in","r",stdin);
    freopen("value.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),s[i]=s[i-1]+a[i];
    q=read();
    int B=min((5000000/n)+1,n);
    if(q==1) B=min((15000000/n)+1,n);
    T.resize(B+1);
    for(int i=1;i<=B;++i) sol(i);
    while(q--){
        int l=read(),r=read();
        pair<int,int> ans={-1,1};
        int w=min(r-l+1,B);
        for(int i=1;i<=w;++i){
            pair<int,int> res=T[i].query(1,i,n,l+i-1,r);
            ans=cmp(ans,res);
        }
        printf("%lld %lld\n",ans.first,ans.second);
    }
    return 0;
}